﻿#include "windowblindsitem.h"

#include <QPainter>
#include <QDebug>

WindowBlindsItem::WindowBlindsItem(QWidget *parent) :
    QLabel(parent)
{
    mTimeLine = new QTimeLine(1000, this);
    connect(mTimeLine, SIGNAL(frameChanged(int)), this, SLOT(timeLineSlot(int)));

    this->setAttribute(Qt::WA_DeleteOnClose);

}


WindowBlindsItem::~WindowBlindsItem()
{

}

void WindowBlindsItem::setImage( const QImage& image )
{
        mDrawImage = image;
}

void WindowBlindsItem::startDraw(const int timeID)
{
    if (!mDrawImage.isNull())
    {
        mTimeLine->setFrameRange(0, mDrawImage.width());
        mTimeLine->startTimer(timeID);
        mTimeLine->start();

    }

}

void WindowBlindsItem::stopDraw()
{
    mTimeLine->stop();

}

void WindowBlindsItem::paintEvent(QPaintEvent *event)
{
    if (!mDrawImage.isNull())
    {
        QPainter painter(this);
        painter.setBrush(QBrush(mCurrentImage));
        painter.setPen(Qt::NoPen);
        painter.drawRect(0, 0, mCurrentWidth, height());
    }

    QLabel::paintEvent(event);
}


void WindowBlindsItem::timeLineSlot(int iVal)
{
    mCurrentImage = mDrawImage.copy(0, 0, iVal, height());
    mCurrentWidth = iVal;

    update();
}
